package com.yixun.controller;

import com.yixun.service.RoleOptService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping(value = "/roleOpt")
public class RoleOptController extends BaseController {

    private final RoleOptService roleOptService;

    public RoleOptController(RoleOptService roleOptService) {
        this.roleOptService = roleOptService;
    }

    /**
     * 根据角色id获取角色对应的权限id
     */
    @RequestMapping(value = "/getOptIDSByRoleID/{role_id}")
    @ResponseBody
    public String getOptIDSByRoleID(@PathVariable(value = "role_id") String role_id){
        return "{\"result\":\""+ roleOptService.getOptIDSByRoleID(role_id) +"\"}";
    }

    /**
     * 给角色关联权限
     */
    @RequestMapping(value = "/insertRoleOpt", method = RequestMethod.POST)
    @ResponseBody
    public boolean insertRoleOpt(@RequestBody Map map){
        int row = roleOptService.insertRoleOpt(this.getSessionUser(), map);
        return row > 0;
    }
}
